package com.ruoyi.testDeal.controller;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.testDeal.domain.report.*;
import com.ruoyi.testDeal.service.TestDealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 业务处理信息Controller
 * 
 * @author lgq
 * @date 2024-3-26
 */
@RestController
@RequestMapping("/testDeal/info")
@Api(value="业务处理信息",tags = "业务处理信息")
public class TestDealController extends BaseController
{
    @Autowired
    private TestDealService testDealService;


    /**
     * 根据项目Id获取业务处理信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('testDeal:info:query')")
    @GetMapping(value = "/{testId}")
    @ApiOperation(value="根据项目Id获取业务处理信息详细信息")
    @ApiImplicitParam(paramType="query", name = "testId", value = "项目Id", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("testId") String testId)
    {
        return success(testDealService.getTestDeal(testId));
    }

    /**
     * 根据项目编号和项目类型获取项目信息和设备信息
     */
    @PreAuthorize("@ss.hasPermi('testDeal:info:query')")
    @GetMapping(value = "/{agreementNum}/{sampleType}")
    @ApiOperation(value="根据项目编号和项目类型获取项目信息和设备信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "agreementNum", value = "项目编号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "sampleType", value = "项目类型", required = true, dataType = "String"),
    })
    public AjaxResult getInfo(@PathVariable("agreementNum") String agreementNum, @PathVariable("sampleType") String sampleType)
    {
        return success(testDealService.getTestInfoByNumAndType(agreementNum, sampleType));
    }

    /**
     * 根据报告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('testDeal:info:query')")
    @GetMapping(value = "/getInfoByReportNum/{reportNum}/{testId}")
    @ApiOperation(value="根据报告编号获取详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "reportNum", value = "报告编号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "testId", value = "项目Id", required = true, dataType = "String"),
    })
    public AjaxResult getInfoByReportNum(@PathVariable("reportNum") String reportNum, @PathVariable("testId") String testId)
    {
        //缠绕提升机
        if(StringUtils.equals("25", testId)) {
            return success(testDealService.getInfoByReportNum(reportNum, testId));
        }
        //空压机
        else if(StringUtils.equals("21", testId)) {
            return success(testDealService.getKyjInfoByReportNum(reportNum, testId));
        }
        //通风机
        else if(StringUtils.equals("23", testId)) {
            return success(testDealService.getTfjInfoByReportNum(reportNum, testId));
        }
        //矿山监测系统
        else if(StringUtils.equals("26", testId)) {
            return success(testDealService.getKshjcjkxtInfoByReportNum(reportNum, testId));
        }
        //水泵
        else if(StringUtils.equals("28", testId)) {
            return success(testDealService.getSbInfoByReportNum(reportNum, testId));
        }
        //防坠器
        else if(StringUtils.equals("29", testId)) {
            return success(testDealService.getFzqInfoByReportNum(reportNum, testId));
        }
        //带式输送机
        else if(StringUtils.equals("30", testId)) {
            return success(testDealService.getDshshsjInfoByReportNum(reportNum, testId));
        }
        return AjaxResult.error("未选择正确的检测项信息");
    }

    /**
     * 根据报告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('testDeal:info:delete')")
    @DeleteMapping (value = "/delByReportNum")
    @ApiOperation(value="根据报告编号获取详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "reportNum", value = "报告编号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "testId", value = "项目Id", required = true, dataType = "String"),
    })
    public AjaxResult delByReportNum(@RequestParam("reportNum") String reportNum, @RequestParam("testId") String testId)
    {
        //缠绕提升机
        if(StringUtils.equals("25", testId)) {
            return success(testDealService.delJkCrtshjInfoByReportNum(reportNum));
        }
        //空压机
        else if(StringUtils.equals("21", testId)) {
            return success(testDealService.delJkKyjInfoByReportNum(reportNum));
        }
        //通风机
        else if(StringUtils.equals("23", testId)) {
            return success(testDealService.delJkTfjInfoByReportNum(reportNum));
        }
        //矿山监测系统
        else if(StringUtils.equals("26", testId)) {
            return success(testDealService.delJkKshjcjkxtInfoByReportNum(reportNum));
        }
        //水泵
        else if(StringUtils.equals("28", testId)) {
            return success(testDealService.delJkSbInfoByReportNum(reportNum));
        }
        //防坠器
        else if(StringUtils.equals("29", testId)) {
            return success(testDealService.delJkFzqInfoByReportNum(reportNum));
        }
        //带式输送机
        else if(StringUtils.equals("30", testId)) {
            return success(testDealService.delJkDshshsjInfoByReportNum(reportNum));
        }
        return AjaxResult.error("未找到当前检测项删除数据");
    }


    /**
     * 非煤缠绕提升机报告导入
     */
    @PostMapping(value = "/importJkCrtshjReport")
    @ApiOperation(value="非煤缠绕提升机报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:JkCrtshj:import')")
    public AjaxResult importJkCrtshjReport(@RequestBody JkCrtshjReportData jkCrtshjReportData)
    {
        return success(testDealService.importJkCrtshj(jkCrtshjReportData));
    }

    /**
     * 非煤缠绕提升机结果保存
     */
    @PostMapping(value = "/saveJkCrtshj")
    @ApiOperation(value="非煤缠绕提升机结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:JkCrtshj:save')")
    public AjaxResult saveJkCrtshj(@RequestBody JkCrtshjReportData jkCrtshjReportData)
    {
        return toAjax(testDealService.saveJkCrtshj(jkCrtshjReportData));
    }

    /**
     * 非煤缠绕提升机结果删除
     */
    @DeleteMapping(value = "/deleteJkCrtshj/{reportNum}")
    @ApiOperation(value="非煤缠绕提升机结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:JkCrtshj:delete')")
    public AjaxResult deleteJkCrtshj(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delJkCrtshjInfoByReportNum(reportNum));
    }

    /**
     *  通用报告图片上传
     */
    @PostMapping(value = "/upload")
    @ApiOperation(value="通用报告图片上传")
    public AjaxResult upload(@RequestPart("file") MultipartFile file, String reportNum) throws IOException {
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(RuoYiConfig.getProfile() + RuoYiConfig.getMediaPath() + "/" + reportNum, file, true);
        return AjaxResult.success(fileName);
    }

    /**
     * 非煤空压机报告导入
     */
    @PostMapping(value = "/importJkKyjReport")
    @ApiOperation(value="非煤空压机报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:JkKyj:import')")
    public AjaxResult importJkKyjReport(@RequestBody JkKyjReportData jkKyjReportData)
    {
        return success(testDealService.importJkKyj(jkKyjReportData));
    }

    /**
     * 非煤空压机结果保存
     */
    @PostMapping(value = "/saveJkKyj")
    @ApiOperation(value="非煤空压机结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:JkKyj:save')")
    public AjaxResult saveJkKyj(@RequestBody JkKyjReportData jkKyjReportData)
    {
        return toAjax(testDealService.saveJkKyj(jkKyjReportData));
    }

    /**
     * 非煤空压机结果删除
     */
    @DeleteMapping(value = "/deleteJkKyj/{reportNum}")
    @ApiOperation(value="非煤空压机结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:JkKyj:delete')")
    public AjaxResult deleteJkKyj(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delJkKyjInfoByReportNum(reportNum));
    }

    /**
     * 非煤通风机报告导入
     */
    @PostMapping(value = "/importJkTfjReport")
    @ApiOperation(value="非煤通风机报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:JkTfj:import')")
    public AjaxResult importJkKyjReport(@RequestBody JkTfjReportData jkTfjReportData)
    {
        return success(testDealService.importJkTfj(jkTfjReportData));
    }

    /**
     * 非煤通风机结果保存
     */
    @PostMapping(value = "/saveJkTfj")
    @ApiOperation(value="非煤通风机结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:JkTfj:save')")
    public AjaxResult saveJkKyj(@RequestBody JkTfjReportData jkTfjReportData)
    {
        return toAjax(testDealService.saveJkTfj(jkTfjReportData));
    }

    /**
     * 非煤通风机结果删除
     */
    @DeleteMapping(value = "/deleteJkTfj/{reportNum}")
    @ApiOperation(value="非煤通风机结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:JkTfj:delete')")
    public AjaxResult deleteJkTfj(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delJkTfjInfoByReportNum(reportNum));
    }

    /**
     * 非煤水泵报告导入
     */
    @PostMapping(value = "/importJkSbReport")
    @ApiOperation(value="非煤水泵报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:JkSb:import')")
    public AjaxResult importJkSbReport(@RequestBody JkSbReportData jkSbReportData)
    {
        return success(testDealService.importJkSb(jkSbReportData));
    }

    /**
     * 非煤水泵结果保存
     */
    @PostMapping(value = "/saveJkSb")
    @ApiOperation(value="非煤水泵结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:JkSb:save')")
    public AjaxResult saveJkSb(@RequestBody JkSbReportData jkSbReportData)
    {
        return toAjax(testDealService.saveJkSb(jkSbReportData));
    }

    /**
     * 非煤水泵结果删除
     */
    @DeleteMapping(value = "/deleteJkSb/{reportNum}")
    @ApiOperation(value="非煤水泵结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:JkSb:delete')")
    public AjaxResult deleteJkSb(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delJkSbInfoByReportNum(reportNum));
    }

    /**
     * 非煤防坠器报告导入
     */
    @PostMapping(value = "/importJkFzqReport")
    @ApiOperation(value="非煤防坠器报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:JkFzq:import')")
    public AjaxResult importJkFzqReport(@RequestBody JkFzqReportData jkFzqReportData)
    {
        return success(testDealService.importJkFzq(jkFzqReportData));
    }

    /**
     * 非煤防坠器结果保存
     */
    @PostMapping(value = "/saveJkFzq")
    @ApiOperation(value="非煤防坠器结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:JkFzq:save')")
    public AjaxResult saveJkFzq(@RequestBody JkFzqReportData jkFzqReportData)
    {
        return toAjax(testDealService.saveJkFzq(jkFzqReportData));
    }

    /**
     * 非煤防坠器结果删除
     */
    @DeleteMapping(value = "/deleteJkFzq/{reportNum}")
    @ApiOperation(value="非煤防坠器结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:JkFzq:delete')")
    public AjaxResult deleteJkFzq(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delJkFzqInfoByReportNum(reportNum));
    }

    /**
     * 非煤带式输送机报告导入
     */
    @PostMapping(value = "/importJkDshshsjReport")
    @ApiOperation(value="非煤带式输送机报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:JkDshshsj:import')")
    public AjaxResult importJkDshshsjReport(@RequestBody JkDshshsjReportData jkDshshsjReportData)
    {
        return success(testDealService.importJkDshshsj(jkDshshsjReportData));
    }

    /**
     * 非煤带式输送机结果保存
     */
    @PostMapping(value = "/saveJkDshshsj")
    @ApiOperation(value="非煤带式输送机结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:JkDshshsj:save')")
    public AjaxResult saveJkDshshsj(@RequestBody JkDshshsjReportData jkDshshsjReportData)
    {
        return toAjax(testDealService.saveJkDshshsj(jkDshshsjReportData));
    }

    /**
     * 非煤带式输送机结果删除
     */
    @DeleteMapping(value = "/deleteJkDshshsj/{reportNum}")
    @ApiOperation(value="非煤带式输送机结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:JkDshshsj:delete')")
    public AjaxResult deleteJkDshshsj(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delJkDshshsjInfoByReportNum(reportNum));
    }

    /**
     * 非煤地下矿山监测监控系统报告导入
     */
    @PostMapping(value = "/importJkKshjcjkxtReport")
    @ApiOperation(value="非煤地下矿山监测监控系统报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:JkKshjcjkxt:import')")
    public AjaxResult importJkKshjcjkxtReport(@RequestBody JkKshjcjkxtReportData jkKshjcjkxtReportData)
    {
        return success(testDealService.importJkKshjcjkxt(jkKshjcjkxtReportData));
    }

    /**
     * 非煤地下矿山监测监控系统结果保存
     */
    @PostMapping(value = "/saveJkKshjcjkxt")
    @ApiOperation(value="非煤地下矿山监测监控系统结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:JkKshjcjkxt:save')")
    public AjaxResult saveJkKshjcjkxt(@RequestBody JkKshjcjkxtReportData jkKshjcjkxtReportData)
    {
        return toAjax(testDealService.saveJkKshjcjkxt(jkKshjcjkxtReportData));
    }

    /**
     * 非煤地下矿山监测监控系统结果删除
     */
    @DeleteMapping(value = "/deleteJkKshjcjkxt/{reportNum}")
    @ApiOperation(value="非煤地下矿山监测监控系统结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:JkKshjcjkxt:delete')")
    public AjaxResult deleteJkKshjcjkxt(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delJkKshjcjkxtInfoByReportNum(reportNum));
    }

    /**
     * 传感器报告导入
     */
    @PostMapping(value = "/importCgq")
    @ApiOperation(value="传感器报告导入")
    @PreAuthorize("@ss.hasPermi('testDeal:Cgq:import')")
    public AjaxResult importCgq(@RequestBody YbReportData ybReportData)
    {
        return success(testDealService.importCgq(ybReportData));
    }

    /**
     * 传感器结果保存
     */
    @PostMapping(value = "/saveCgq")
    @ApiOperation(value="传感器结果保存")
    @PreAuthorize("@ss.hasPermi('testDeal:Cgq:save')")
    public AjaxResult saveCgq(@RequestBody YbReportData ybReportData)
    {
        return toAjax(testDealService.saveCgq(ybReportData));
    }

    /**
     * 传感器结果删除
     */
    @DeleteMapping(value = "/delCgqByReportNum/{reportNum}")
    @ApiOperation(value="传感器结果删除")
    @PreAuthorize("@ss.hasPermi('testDeal:Cgq:delete')")
    public AjaxResult delCgqByReportNum(@PathVariable String reportNum)
    {
        return toAjax(testDealService.delCgqByReportNum(reportNum));
    }


    /**
     * 根据报告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('testDeal:ybinfo:query')")
    @GetMapping(value = "/getYbByReportNum/{reportNum}")
    @ApiOperation(value="根据报告编号获取详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "reportNum", value = "报告编号", required = true, dataType = "String"),
    })
    public AjaxResult getYbByReportNum(@PathVariable("reportNum") String reportNum)
    {

        return AjaxResult.success(testDealService.getYbInfoByReportNum(reportNum));
    }
}
